Date-Time Arithmetic
AppleScript supports these operations with the + and - operators on date and time difference values:
date + timeDifference --result: date date - date --result: timeDifference date - timeDifference --result: datewhere date is a date value and timeDifference is an integer value specifying a time difference in seconds.To simplify the notation of time differences, you can also use one or more of these constants:
minutes 60 hours 60 * minutes days 24 * hours weeks 7 * days Here's an example:
date "Apr 15, 1992" + 4 * days + 3 * hours + 2 * minutesIt is often useful to be able to specify a time difference between two dates;
for example:
set timeInvestment to current date - "May 16, 1992"After running this script, the value of thetimeInvestment
variable is an integer that specifies the number of seconds between the two dates. If you then add this time difference to the starting date (May 16, 1992), AppleScript returns a date value equal to the current date when thetimeInvestment
variable was set.To express a time difference in more convenient form, divide the number of seconds by the appropriate constant:
31449600 / years --result: 1 151200 / days --result: 1.75To get an integral number of hours, days, and so on, use thediv
operator:
151200 div days --result: 1To get the difference, in seconds, between the current time and Greenwich mean time, use the scripting addition command Time to GMT. For example, if you are in Cupertino, California, and your computer is set to Pacific Standard Time, Time to GMT produces this result:
time to GMT --result: -28800For more information about the Time to GMT command, see the AppleScript Scripting Additions Guide.